package com.example.demo.Test;

import com.example.demo.bean.User;
import com.example.demo.service.UserDao;
import com.example.demo.DemoApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class)
public class UserDaoTest_user {


    @Autowired
    private UserDao userDao;
    long findid;

    @Test
  /*  public void testInsert(){
        User user = new User();
       // user.setId(1L);
        user.setName("wangwu");
        user.setAmount(201);
        user.setPrice(20.1);
        userDao.add(user);
        System.out.println("插入功能完成！");
    }*/

    public void testInsert(){
        User user = new User();
        // user.setId(1L);
        user.setScore(234);
        user.setLevel(3);
        user.setBalance(20.1);
        userDao.add(user);
        System.out.println("插入功能完成！");
    }

    @Test
  /*  public void testUpdate(){
        User user = new User();
        user.setId((long) 1);
        user.setName("zhaoliu");
        user.setAmount(203);
        user.setPrice(20.3);
        System.out.println(userDao.update(user));
        System.out.println("更新功能完成！");
    }*/

    public void testUpdate(){
        User user = new User();
        user.setId((long) 1);
        user.setScore(350);
        user.setLevel(3);
        user.setBalance(20.3);
        System.out.println(userDao.update(user));
        System.out.println("更新功能完成！");
    }


    @Test
    public void testDel(){
        userDao.del((long) 8);
        System.out.println("删除功能完成！");
    }


    @Test
 /*   public void testFindUserById(){
        User user = userDao.findUserById((long) 1);
        System.out.println(user.getName()+","+user.getAmount()+","+user.getPrice());
        System.out.println("通过id查找功能完成！");
    }*/

    public void testFindUserById(){
        User user = userDao.findUserById(findid);
       // User user = userDao.findUserById((long) 1);
        System.out.println(user.getScore()+","+user.getLevel()+","+user.getBalance());
        System.out.println("通过id查找功能完成！");
    }


    @Test
   /* public void testFindUserList(){
        List<User> userList = userDao.findUserList();
        for (User usertmp:userList) {
            System.out.println(usertmp.getName()+","+usertmp.getAmount()+","+usertmp.getPrice());
        }
        System.out.println("查找用户列表功能完成！");
    }*/

    public void testFindUserList(){
        List<User> userList = userDao.findUserList();
        for (User usertmp:userList) {
            System.out.println(usertmp.getScore()+","+usertmp.getLevel()+","+usertmp.getBalance());
        }
        System.out.println("查找用户列表功能完成！");
    }
}
